﻿namespace UsefulTools.Wpf
{
    #region Usings

    using System;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Threading;
    using UsefulTools.Core;

    #endregion

    public class DispatcherExecute : IDispatcherExecute
    {
        private TaskScheduler _guiScheduler;
        private SynchronizationContext _syncContext;

        public TaskScheduler GuiScheduler
        {
            get
            {
                return _guiScheduler;
            }
        }

        public SynchronizationContext GuiSyncContext
        {
            get
            {
                return _syncContext;
            }
        }

        /// <summary>
        /// Must be called on dispatcher thread.
        /// </summary>
        public void InitializeWithDispatcher()
        {
            _guiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
            _syncContext = SynchronizationContext.Current;
        }
    }
}